/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package POJOS;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;

/**
 *
 * @author John
 */
public class TipoIncidenciaAction extends ActionSupport implements ModelDriven<TipoIncidencia> {
    
    private TipoIncidencia tipoIncidencia = new TipoIncidencia();
    private List<TipoIncidencia> listaTipoIncidencias = new ArrayList<TipoIncidencia>();
    private TipoIncidenciaDAO tipoIncidenciaDAO = new TipoIncidenciaDAO();
    
    public TipoIncidenciaAction() {
    }
    
    /*public String execute() throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }*/

    @Override
    public TipoIncidencia getModel() {
        //throw new UnsupportedOperationException("Not supported yet.");
        return tipoIncidencia;
    }
    
    /**
     * To save or update user.
     * @return String
     */
    public String guardarOActualizar()
    {	
        tipoIncidenciaDAO.guardarOActualizarTipoIncidencia(tipoIncidencia);
        return SUCCESS;
    }

    /**
     * To list all users.
     * @return String
     */
    public String listar()
    {
        listaTipoIncidencias = tipoIncidenciaDAO.listarTipoIncidencias();
        return SUCCESS;
    }

    /**
     * To delete a user.
     * @return String
     */
    public String eliminar()
    {
        HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
        tipoIncidenciaDAO.eliminarTipoIncidencia(Long.parseLong(request.getParameter("id")));
        return SUCCESS;
    }

    /**
     * To list a single user by Id.
     * @return String
     */
    public String editar()
    {
        HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
        tipoIncidencia = tipoIncidenciaDAO.listarTipoIncidenciaPorId(Long.parseLong(request.getParameter("id")));
        return SUCCESS;
    }

    public TipoIncidencia getTipoIncidencia() {
        return tipoIncidencia;
    }

    public void setTipoIncidencia(TipoIncidencia tipoIncidencia) {
        this.tipoIncidencia = tipoIncidencia;
    }

    public List<TipoIncidencia> getListaTipoIncidencias() {
        return listaTipoIncidencias;
    }

    public void setListaTipoIncidencias(List<TipoIncidencia> listaTipoIncidencias) {
        this.listaTipoIncidencias = listaTipoIncidencias;
    }
}
